Public Class UIConfigDialog

    ' TODO: add a file Browse dialog control to configure a viable Image Editor program - we could just use Paint.NET since it's free and has the same .NET dependency as this add-in
    '       In fact, the add-in could just look for Paint.NET, and if it doesn't find it, it could open a dialog for another app

    ' TODO: Add guard-code around the input from the user, to prevent any unexpected inputs.

    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        GetUserConfigurationSettings()

        PopulateCheckboxes()

    End Sub

#Region " Event Handlers "

    Private Sub uiOKButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uiOKButton.Click
        ' TODO: Read back out the values of the checkboxes and set the values of the corresponding user Settings

        ReadFromCheckboxes(e)

        SetUserConfigurationSettings()

    End Sub

    Private Sub uiCancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uiCancelButton.Click

        ' Just exit the form, with no changes
        Me.Close()

    End Sub

#End Region

#Region " Private Subs "

    Private Sub GetUserConfigurationSettings()
        ' TODO: read in all values from the Project's Settings (XML)
        ' 
        ' AllowWikiCharacters: User wants to 
        ' ArticleCategory: this is the MediaWiki category that will be assigned to the article when it is published on the Wiki.  Multiple categories must be comma-delimited.
        ' CategoryPrefixForImages: this is a prefix to be pre-pended to the category string that will be assigned to Image references in the Wiki article.
        ' ConvertFontSizes: User wants to preserve the relative sizing of the Fonts used in the current document, so the size differences in the text show up in the current document.
        ' DeleteHiddenText: User wants to remove/delete all text that has the Hidden attribute throughout the current document.
        ' RequireCategories: User wants to ensure that all articles uploaded to the Wiki have at least one Category assigned.
        ' SetListLevelManually: User wants to override the "list level", which will remove the "indentation" from a bulleted or numbered List.
        ' UseBrBrForNewParagraph: User prefers to use <br> <br> characters rather than the typical <p> approach for a "new line".  Note that the use of <br> <br> is NOT preferred MediaWiki style.
        ' UseTheArticleCategory: User wants to enable the use of the Category specified in ArticleCategory; otherwise, the user doesn't want a Category used.

    End Sub

    Private Sub PopulateCheckboxes()
        ' TODO: translate the current user settings into the values for the corresponding checkboxes, and set the checkboxes accordingly before the Form is fully drawn.

        uiAllowWikiCharacters.Checked = My.Settings.AllowWikiCharacters
        uiCategoryTextBoxArticle.Text = My.Settings.ArticleCategory
        uiCategoryTextboxImagePrefix.Text = My.Settings.CategoryPrefixForImages
        uiConvertFontSize.Checked = My.Settings.ConvertFontSizes
        uiDeleteHiddenText.Checked = My.Settings.DeleteHiddenText
        uiRequireCategories.Checked = My.Settings.RequireCategories
        uiSetListLevelManually.Checked = My.Settings.SetListLevelManually
        uiUseBrBrForNewParagraph.Checked = My.Settings.UseBrBrForNewParagraph
        uiCheckboxUseCategory.Checked = My.Settings.UseTheArticleCategory

        ' Now disable the ArticleCategory textbox if the UseTheArticleCategory checkbox is unchecked
        If My.Settings.UseTheArticleCategory = False Then
            uiCategoryTextBoxArticle.Enabled = False
        Else
            uiCategoryTextBoxArticle.Enabled = True
        End If

    End Sub

    Private Sub ReadFromCheckboxes(ByVal arguments As System.EventArgs)
        ' TODO: translate the submitted checkbox values into the corresponding user settings

        My.Settings.AllowWikiCharacters = uiAllowWikiCharacters.Checked
        ' Whitespace in a Category is bad, m'kay?
        My.Settings.ArticleCategory = Trim(uiCategoryTextBoxArticle.Text)
        My.Settings.CategoryPrefixForImages = Trim(uiCategoryTextboxImagePrefix.Text)
        My.Settings.ConvertFontSizes = uiConvertFontSize.Checked
        My.Settings.DeleteHiddenText = uiDeleteHiddenText.Checked
        My.Settings.RequireCategories = uiRequireCategories.Checked
        My.Settings.SetListLevelManually = uiSetListLevelManually.Checked
        My.Settings.UseBrBrForNewParagraph = uiUseBrBrForNewParagraph.Checked
        My.Settings.UseTheArticleCategory = uiCheckboxUseCategory.Checked

    End Sub

    Private Sub SetUserConfigurationSettings()
        ' TODO: write all user setting values back to XML settings file

    End Sub

#End Region

    Private Sub uiUseTheArticleCategory_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles uiCheckboxUseCategory.CheckedChanged
        ' This will grey out the Category textbox if the checkbox is unchecked, which helps reinforce the purpose of this checkbox
        If uiCheckboxUseCategory.Checked = False Then
            uiCategoryTextBoxArticle.Enabled = False
        Else
            uiCategoryTextBoxArticle.Enabled = True
        End If
    End Sub
End Class
